<template>
  <div class="home-wrap">
    <div class="data-wrap">
      <div class="data-box">
        <div class="data-item">
          <div class="data-icon">
            <img src="../../assets//img/info1.png" />
          </div>
          <div class="data-info">
            <div class="data-count">{{ carInfo.countCarTime }}</div>
            <div class="data-label">总车次</div>
          </div>
        </div>
        <div class="data-item">
          <div class="data-icon">
            <img src="../../assets//img/info2.png" />
          </div>
          <div class="data-info">
            <div class="data-count">{{ carInfo.todayCountCarTime }}</div>
            <div class="data-label">今日车次</div>
          </div>
        </div>
        <div class="data-item">
          <div class="data-icon">
            <img src="../../assets//img/info3.png" />
          </div>
          <div class="data-info">
            <div class="data-count">{{ carInfo.countCarAbnormal }}</div>
            <div class="data-label">总异常车次</div>
          </div>
        </div>
        <div class="data-item">
          <div class="data-icon">
            <img src="../../assets//img/info4.png" />
          </div>
          <div class="data-info">
            <div class="data-count">{{ carInfo.todayCountCarAbnormal }}</div>
            <div class="data-label">今日异常车次</div>
          </div>
        </div>
        <div class="data-item">
          <div class="data-icon">
            <img src="../../assets//img/info5.png" />
          </div>
          <div class="data-info">
            <div class="data-count">{{ carInfo.countCarNum }}</div>
            <div class="data-label">车辆</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 运输概况 -->
    <div class="overview-wrap">
      <div class="title"></div>
      <div class="chart-wrap">
        <div class="border"></div>
        <div class="title">
          <span>每日运输车次</span>
          <img src="../../assets/img/title_icon.png" />
        </div>
        <div class="overview-box" ref="overviewRef"></div>
      </div>
      <div class="chart-wrap">
        <div class="border"></div>
        <div class="title">
          <span>运输车次趋势</span>
          <img src="../../assets/img/title_icon.png" />
        </div>
        <div class="overview-box" ref="trendRef"></div>
      </div>
    </div>
    <!-- 运输情况 -->
    <div class="situation-wrap">
      <div class="title"></div>
      <div class="transport-wrap">
        <div class="transport-box">
          <div class="transport-list">
            <vue-seamless-scroll
              :data="transportData"
              :class-option="defaultOption"
            >
              <div
                class="transport-item"
                v-for="(item, index) in transportData"
                :key="index"
              >
                <div class="border"></div>
                <div class="transport-info">
                  <div class="transport-title">
                    <span>基本信息</span>
                    <img src="../../assets/img/title_icon.png" />
                  </div>
                  <div class="transport-text-box">
                    <div class="transport-text">
                      <div class="transport-label">车牌号:</div>
                      <div class="transport-code">{{ item.carCode }}</div>
                    </div>
                    <div class="transport-text">
                      <div class="transport-label">时间:</div>
                      <div class="transport-code">
                        {{ item.photographTime }}
                      </div>
                    </div>
                  </div>
                </div>
                <div class="transport-image">
                  <el-image
                    class="transport-el-image"
                    :src="item.coachUrl"
                    :preview-src-list="[item.coachUrl]"
                  >
                  </el-image>
                </div>
              </div>
            </vue-seamless-scroll>
          </div>
        </div>
      </div>
    </div>

    <!-- 地图 -->
    <homeMap></homeMap>
  </div>
</template>
<script>
import homeMap from "./homeMap.vue";
import vueSeamlessScroll from "vue-seamless-scroll";
import echarts from "echarts";
import * as echarts5 from "echarts5";
export default {
  data() {
    return {
      carInfo: {
        countCarTime: 0,
        countCarAbnormal: 0,
        countCarNum: 0,
        todayCountCarTime: 0,
        todayCountCarAbnormal: 0
      },
      defaultOption: {
        step: 0.2,
        limitMoveNum: 2,
        hoverStop: true,
        direction: 1,
        openWatch: true,
        singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动)
        singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动)
        waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
      },
      transportData: [],
      pageParams: {
        page: 1,
        limit: 10,
        home: 1,
        selectAll: 1,
        auditstatus: 1
      },
      timer: null,
      overviewChart: null,
      trendChart: null,
      url: require("../../assets/img/car.png"),
      srcList: [require("../../assets/img/car.png")]
    };
  },
  components: {
    homeMap,
    vueSeamlessScroll
  },
  watch: {},
  created() {},
  activated() {
    this.getChartData();
    this.getTrendData();
  },
  mounted() {
    this.getCarInfo();
    this.getDataList();
    this.timer = setInterval(() => {
      this.getDataList();
    }, 120000);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },

  methods: {
    // 获取考勤
    getCarInfo() {
      this.$http({
        url: this.$http.adornUrl(`/generator/bcarledger/homeCountData`),
        method: "get"
      }).then(({ data }) => {
        if (data) {
          this.carInfo = { ...this.carInfo, ...data };
        }
      });
    },
    // 获取数据列表
    getDataList() {
      this.$http({
        url: this.$http.adornUrl("/generator/bcarledger/page"),
        method: "get",
        params: this.$http.adornParams(this.pageParams)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.transportData = data.page.list;
        } else {
          this.transportData = [];
        }
      });
    },

    // 获取车辆概况
    getOverview(x, y, z) {
      if (this.overviewChart) {
        this.overviewChart.dispose();
      }
      this.overviewChart = echarts.init(this.$refs.overviewRef);
      let option = {
        color: ["#3E8EF7", "#FE9152"],
        legend: {
          top: "10",
          right: "40",
          data: ["正常车次", "异常车次"],
          textStyle: {
            color: "#D5F6FF"
          }
        },
        xAxis: {
          type: "category",
          data: x,
          axisLabel: {
            color: "#D5F6FF",
            fontSize: 12
          }
        },
        yAxis: {
          name: "车次",
          nameGap: 16,
          nameTextStyle: {
            color: "#D5F6FF"
          },
          type: "value",
          axisLabel: {
            color: "#D5F6FF",
            fontSize: 12
          },
          axisLine: {
            lineStyle: {
              color: "#23436f"
            }
          },
          splitLine: {
            lineStyle: {
              type: "dashed",
              color: "#23436f"
            }
          }
        },
        series: [
          {
            name: "正常车次",
            data: y,
            type: "bar"
          },
          {
            name: "异常车次",
            data: z,
            type: "bar"
          }
        ]
      };
      option && this.overviewChart.setOption(option);
    },
    //获取运输车次趋势
    getTrend(x, y, z) {
      if (this.trendChart) {
        this.trendChart.dispose();
      }
      this.trendChart = echarts5.init(this.$refs.trendRef);
      let option = {
        legend: {
          top: "10",
          right: "40",
          data: ["正常车次", "异常车次"],
          icon: "rect",
          itemHeight: 2,
          textStyle: {
            color: "#D5F6FF"
          }
        },
        xAxis: {
          type: "category",
          data: x,
          axisLabel: {
            color: "#D5F6FF",
            fontSize: 12
          }
        },
        yAxis: {
          name: "车次",
          nameGap: 16,
          nameTextStyle: {
            color: "#D5F6FF"
          },
          type: "value",
          axisLabel: {
            color: "#D5F6FF",
            fontSize: 12
          },
          axisLine: {
            lineStyle: {
              color: "#23436f"
            }
          },
          splitLine: {
            lineStyle: {
              type: "dashed",
              color: "#23436f"
            }
          }
        },
        series: [
          {
            name: "正常车次",
            data: y,
            type: "line",
            smooth: true,
            color: "#3E8EF7",
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "rgba(62,142,247,1)"
                },
                {
                  offset: 1,
                  color: "rgba(0,108,117,0)"
                }
              ])
            }
          },
          {
            name: "异常车次",
            data: z,
            type: "line",
            smooth: true,
            color: "#FE9152",
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#FE9152"
                },
                {
                  offset: 1,
                  color: "rgba(254,145,82,0)"
                }
              ])
            }
          }
        ]
      };
      option && this.trendChart.setOption(option);
    },
    getChartData() {
      this.$http({
        url: this.$http.adornUrl("/generator/bcarledger/homeTransportData"),
        method: "get",
        params: this.$http.adornParams()
      }).then(res => {
        if (res.data) {
          let xList = [];
          let yList1 = [];
          let yList2 = [];
          res.data.forEach((item, index) => {
            xList.push(item.day);
            yList1.push(item.normalCount);
            yList2.push(item.abnormalCount);
          });
          this.$nextTick(() => {
            this.getOverview(xList, yList1, yList2);
          });
        }
      });
    },
    getTrendData() {
      this.$http({
        url: this.$http.adornUrl("/generator/bcarledger/homeCarTendency"),
        method: "get",
        params: this.$http.adornParams()
      }).then(res => {
        if (res.data) {
          let xList = [];
          let yList1 = [];
          let yList2 = [];
          res.data.forEach((item, index) => {
            xList.push(item.day);
            yList1.push(item.normalCount);
            yList2.push(item.abnormalCount);
          });
          this.$nextTick(() => {
            this.getTrend(xList, yList1, yList2);
          });
        }
      });
    }
  }
};
</script>
<style lang="scss">
.home-wrap {
  position: relative;
  width: 100%;
  height: calc(100vh - 124px);
  background: url("../../assets/img/home_bg.png") center center no-repeat;
  background-size: 100% 100%;
  .data-wrap {
    border-radius: 8px;
    padding: 12px 0;
    .data-box {
      display: flex;
      .data-item {
        display: flex;
        flex: 0 0 18.4%;
        padding: 16px 18px;
        background: url("../../assets/img/info_bg.png") center center no-repeat;
        background-size: 100% 100%;
        &:nth-child(1) {
          margin-right: 1%;
        }
        &:nth-child(2) {
          margin: 0 1%;
        }
        &:nth-child(3) {
          margin: 0 1%;
        }
        &:nth-child(4) {
          margin: 0 1%;
        }
        &:nth-child(5) {
          margin-right: 1%;
        }
        .data-icon {
          width: 68px;
          height: 68px;

          img {
            width: 100%;
            height: 100%;
          }
        }
        .data-info {
          margin-left: 20px;
          padding-top: 6px;
          .data-count {
            margin-top: 4px;
            color: #fff;
            line-height: 1;
            font-size: 30px;
            font-weight: 700;
            margin-bottom: 12px;
          }
          .data-label {
            font-size: 14px;
            color: #fff;
            line-height: 1;
          }
        }
      }
    }
  }
  .overview-wrap {
    position: absolute;
    top: 146px;
    left: 16px;
    z-index: 1;
    .title {
      width: 462px;
      height: 100px;
      background: url("../../assets/img/title1.png") center center no-repeat;
      background-size: 100% 100%;
    }
    .chart-wrap {
      position: relative;
      background-color: #01214b;
      width: 462px;
      height: 286px;
      padding-top: 20px;
      margin-bottom: 20px;
      .border {
        position: absolute;
        top: -4px;
        width: 462px;
        height: 8px;
        background: url("../../assets/img/border.png") center center no-repeat;
        background-size: 100% 100%;
      }
      .title {
        display: flex;
        align-items: center;
        margin-left: 22px;
        width: 199px;
        height: 27px;
        padding-left: 8px;
        background: url("../../assets/img/title3.png") center center no-repeat;
        background-size: 100% 100%;
        color: #fff;
        font-size: 14px;
        font-weight: 500;

        img {
          width: 19px;
          height: 9px;
          margin-left: 3px;
        }
      }
      .overview-box {
        width: 480px;
        height: 268px;
      }
    }
  }
  .situation-wrap {
    position: absolute;
    top: 146px;
    right: 16px;
    z-index: 1;
    .title {
      width: 462px;
      height: 100px;
      background: url("../../assets/img/title2.png") center center no-repeat;
      background-size: 100% 100%;
    }
    .transport-wrap {
      .transport-box {
        border-radius: 8px;
        padding: 20px;

        .transport-list {
          height: 570px;
          overflow: hidden;
          .transport-item {
            display: flex;
            width: 464px;
            min-height: 200px;
            position: relative;
            margin-bottom: 20px;
            padding: 22px 10px;
            background-color: #01214b;
            .border {
              position: absolute;
              top: -4px;
              width: 462px;
              height: 8px;
              background: url("../../assets/img/border.png") center center
                no-repeat;
              background-size: 100% 100%;
            }
            .transport-image {
              width: 236px;
              height: 156px;
              border: 1px solid #3e8ef7;
              padding: 2px;
              img {
                width: 100%;
                height: 100%;
                border-radius: 12px;
              }
              .transport-el-image {
                width: 236px;
                height: 156px;
              }
            }
            .transport-info {
              margin-right: 10px;

              .transport-title {
                display: flex;
                align-items: center;
                margin-bottom: 6px;
                width: 199px;
                height: 27px;
                padding-left: 8px;
                background: url("../../assets/img/title3.png") center center
                  no-repeat;
                background-size: 100% 100%;
                color: #fff;
                font-size: 14px;
                font-weight: 500;

                img {
                  width: 19px;
                  height: 9px;
                  margin-left: 3px;
                }
              }
              .transport-text-box {
                padding: 8px 5px 20px;
                border: 1px solid #1d497f;
                background-color: #092f61;
                .transport-text {
                  display: flex;
                  line-height: 45px;
                  border-bottom: 1px dashed #1d497f;
                  .transport-label {
                    margin-right: 12px;
                    font-size: 14px;
                    color: #fff;
                    line-height: 45px;
                  }
                  .transport-code {
                    color: #3e8ef7;
                    font-size: 14px;
                    line-height: 45px;
                    letter-spacing: 0.28px;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

@media only screen and (max-width: 1366px) {
  .home-wrap {
    position: relative;
    height: calc(100vh - 54px);
    .data-wrap {
      border-radius: 8px;
      padding: 12px 0;
      .data-box {
        display: flex;
        .data-item {
          display: flex;
          flex: 0 0 18.4%;
          padding: 16px 18px;
          background: url("../../assets/img/info_bg.png") center center
            no-repeat;
          background-size: 100% 100%;
          &:nth-child(1) {
            margin-right: 1%;
          }
          &:nth-child(2) {
            margin: 0 1%;
          }
          &:nth-child(3) {
            margin: 0 1%;
          }
          &:nth-child(4) {
            margin: 0 1%;
          }
          &:nth-child(5) {
            margin-right: 1%;
          }
          .data-icon {
            width: 48px;
            height: 48px;

            img {
              width: 100%;
              height: 100%;
            }
          }
          .data-info {
            margin-left: 12px;
            padding-top: 2px;
            .data-count {
              margin-top: 4px;
              color: #fff;
              line-height: 1;
              font-size: 24px;
              font-weight: 700;
              margin-bottom: 6px;
            }
            .data-label {
              font-size: 12px;
              color: #fff;
              line-height: 1;
            }
          }
        }
      }
    }
    .overview-wrap {
      position: absolute;
      top: 97px;
      left: 11px;
      z-index: 1;
      .title {
        width: 308px;
        height: 67px;
        background: url("../../assets/img/title1.png") center center no-repeat;
        background-size: 100% 100%;
      }
      .chart-wrap {
        position: relative;
        background-color: #01214b;
        width: 308px;
        height: 191px;
        padding-top: 13px;
        margin-bottom: 13px;
        .border {
          position: absolute;
          top: -3px;
          width: 308px;
          height: 5px;
          background: url("../../assets/img/border.png") center center no-repeat;
          background-size: 100% 100%;
        }
        .title {
          display: flex;
          align-items: center;
          margin-left: 15px;
          width: 133px;
          height: 18px;
          padding-left: 5px;
          background: url("../../assets/img/title3.png") center center no-repeat;
          background-size: 100% 100%;
          color: #fff;
          font-size: 12px;
          font-weight: 500;

          img {
            width: 13px;
            height: 6px;
            margin-left: 3px;
          }
        }
        .overview-box {
          width: 320px;
          height: 200px;
        }
      }
    }
    .situation-wrap {
      position: absolute;
      top: 97px;
      right: 11px;
      z-index: 1;
      .title {
        width: 308px;
        height: 67px;
        background: url("../../assets/img/title2.png") center center no-repeat;
        background-size: 100% 100%;
      }
      .transport-wrap {
        .transport-box {
          border-radius: 8px;
          padding: 0 13px 13px;

          .transport-list {
            height: 380px;
            overflow: hidden;
            .transport-item {
              display: flex;
              width: 309px;
              min-height: 133px;
              position: relative;
              margin-bottom: 13px;
              padding: 15px 7px;
              background-color: #01214b;
              .border {
                position: absolute;
                top: -4px;
                width: 380px;
                height: 5px;
                background: url("../../assets/img/border.png") center center
                  no-repeat;
                background-size: 100% 100%;
              }
              .transport-image {
                width: 157px;
                height: 104px;
                border: 1px solid #3e8ef7;
                padding: 1px;
                img {
                  width: 100%;
                  height: 100%;
                  border-radius: 12px;
                }
                .transport-el-image {
                  width: 157px;
                  height: 104px;
                }
              }
              .transport-info {
                margin-right: 7px;

                .transport-title {
                  display: flex;
                  align-items: center;
                  margin-bottom: 6px;
                  width: 133px;
                  height: 18px;
                  padding-left: 5px;
                  background: url("../../assets/img/title3.png") center center
                    no-repeat;
                  background-size: 100% 100%;
                  color: #fff;
                  font-size: 12px;
                  font-weight: 500;

                  img {
                    width: 13px;
                    height: 6px;
                    margin-left: 2px;
                  }
                }
                .transport-text-box {
                  padding: 5px 3px 13px;
                  border: 1px solid #1d497f;
                  background-color: #092f61;
                  .transport-text {
                    display: flex;
                    line-height: 30px;
                    border-bottom: 1px dashed #1d497f;
                    .transport-label {
                      margin-right: 12px;
                      font-size: 12px;
                      color: #fff;
                      line-height: 30px;
                      width: 40px;
                    }
                    .transport-code {
                      color: #3e8ef7;
                      font-size: 12px;
                      line-height: 30px;
                      letter-spacing: 0.28px;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
